home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Examples / DrawShapes / UMenu.p < prev   
Encoding:
Text File  |  1990-10-25  |  5.2 KB  |  163 lines  |  [TEXT/MPS ]

  1. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
  2. { UMenu.p }
  3. { Copyright © 1989-1990 by Apple Computer Inc. All rights reserved. }
  4.  
  5. {[f-]}
  6. (*
  7.         T H E O R Y   O F    O P E R A T I O N
  8.  
  9. This is Larry Rosenstein's excellent unit: UMenu, that supports an
  10. object-oriented way of defining custom menus.
  11.  
  12. Instead of writing a menu defproc, you simply create a subtype of TMenu
  13. and override certain methods.  Not only is this easier to program,
  14. but this unit takes care of some of the housekeeping that a menu
  15. defproc would normally have to do.
  16. *)
  17. {[f+]}
  18.  
  19. UNIT UMenu;
  20.  
  21.     INTERFACE
  22.  
  23.         USES
  24.             { • MacApp}
  25.             UMacApp,
  26.             {}
  27.             Errors;
  28.  
  29.         CONST
  30.             kNoMenuItem         = 0;                    { used to indicate that no item is selected
  31.                                                          }
  32.  
  33.         TYPE
  34.  
  35.             MenuColors            = RECORD                { a composite of the MCEntries }
  36.                 itemColor:            RGBColor;            { the foreground color to draw the item with
  37.                                                          (the color of the title if title or
  38.                                                          menubar) }
  39.                 backgroundColor:    RGBColor;            { the background color to draw the item with
  40.                                                          (the color of the menubar if title or
  41.                                                          menubar)}
  42.                 markColor:            RGBColor;            { the foreground color to draw the mark with
  43.                                                          (checkmarks, etc.) }
  44.                 commandColor:        RGBColor;            { the foreground color to draw the command
  45.                                                          key equivalent with (command-v for paste,
  46.                                                          etc).}
  47.                 END;
  48.             MenuColorsPtr        = ^MenuColors;
  49.             MenuColorsHandle    = ^MenuColorsPtr;
  50.  
  51.             TMenu                = OBJECT (TView)
  52.                 fMenuHandle:        MenuHandle;         { handle to menu itself }
  53.                 fFlashInterval:     LONGINT;            { Time (in ticks) between flashes of item
  54.                                                          highlighting; default is -1 which means
  55.                                                          only change highlighting w when item
  56.                                                          changes }
  57.                 fNextFlash:         LONGINT;            { Used internally }
  58.                 fMenuRect:            Rect;                { menuRect that was last passed to the MDef
  59.                                                          }
  60.                 fHitPt:             Point;                { hitPt that was last passed to the MDef.
  61.                                                          gets offset in Focus. }
  62.                 fHighlighted:        BOOLEAN;            { True if an item is highlighted }
  63.                 fBorder:            Rect;                { Added to menuRect to get actual hit rect;
  64.                                                          FindItem will not be called if the mouse
  65.                                                          is in the border. }
  66.  
  67.                                 { Initialization }
  68.  
  69.                 PROCEDURE TMenu.IMenu(rsrcID: INTEGER;
  70.                                       menuWidth, menuHeight: INTEGER);
  71.                 { IMenu reads the menu and sets up the MenuHandle and defproc
  72.                   so that the Menu Manager can communicate with the TMenu object.
  73.                  }
  74.  
  75.                 { Menu Definition; all these methods must be overridden }
  76.  
  77.                 FUNCTION TMenu.FindItem(hitPt: Point): INTEGER;
  78.                 { This is called to convert a point to an item number. }
  79.  
  80.                 PROCEDURE TMenu.Highlight(whichItem: INTEGER;
  81.                                           turnItOn: BOOLEAN);
  82.                 { Given an item number as returned by FindItem, this is called
  83.                 to highlight the item.    This will not be called with
  84.                 whichItem = kNoMenuItem. }
  85.  
  86.                 { Other methods }
  87.  
  88.                 PROCEDURE TMenu.GetMenuColors(theMenu, theItem: INTEGER;
  89.                                               VAR theMenuColors: MenuColors);
  90.                 { Called to get the appropriate menu colors for the menu and item.
  91.                 If the menu and item are 0 then info is for the menubar.
  92.                 If item is 0 then info is for the menu title.
  93.                 Attempts to return best guess at colors based on all available info. }
  94.  
  95.                 FUNCTION TMenu.IsItemEnabled(item:INTEGER): Boolean;
  96.                 { Returns the enabled status of an item }
  97.  
  98.                 PROCEDURE TMenu.UpdateHighlight(oldItem, newItem: INTEGER);
  99.                 { Called to update menu item highlighting. }
  100.  
  101.                 { Private }
  102.  
  103.                 PROCEDURE TMenu.HandleDefproc(message: INTEGER;
  104.                                               theMenu: MenuHandle;
  105.                                               VAR menuRect: Rect;
  106.                                               hitPt: Point;
  107.                                               VAR whichItem: INTEGER);
  108.                 { This is called by the custom defproc; it does a CASE
  109.                 on the message and calls 1 or more of the methods above. }
  110.  
  111.                 PROCEDURE TMenu.HandleChooseMessage(message: INTEGER;
  112.                                                     theMenu: MenuHandle;
  113.                                                     VAR menuRect: Rect;
  114.                                                     hitPt: Point;
  115.                                                     VAR whichItem: INTEGER);
  116.                 { Called by the message dispatcher when a choose message has been sent }
  117.  
  118.                 PROCEDURE TMenu.HandleDrawMessage(message: INTEGER;
  119.                                                   theMenu: MenuHandle;
  120.                                                   VAR menuRect: Rect;
  121.                                                   hitPt: Point;
  122.                                                   VAR whichItem: INTEGER);
  123.                 { Called by the message dispatcher when a draw message has been sent }
  124.  
  125.                 PROCEDURE TMenu.HandleSizeMessage(message: INTEGER;
  126.                                                   theMenu: MenuHandle;
  127.                                                   VAR menuRect: Rect;
  128.                                                   hitPt: Point;
  129.                                                   VAR whichItem: INTEGER);
  130.                 PROCEDURE TMenu.HandlePopUpMessage(message: INTEGER;
  131.                                                    theMenu: MenuHandle;
  132.                                                    VAR menuRect: Rect;
  133.                                                    hitPt: Point;
  134.                                                    VAR whichItem: INTEGER);
  135.                 { Focusing Methods }
  136.  
  137.                 FUNCTION TMenu.Focus: BOOLEAN; OVERRIDE;
  138.  
  139.                 FUNCTION TMenu.FocusOnSuperView: BOOLEAN; OVERRIDE;
  140.  
  141.                 { Misc. Methods }
  142.  
  143.                 FUNCTION TMenu.GetGrafPort: GrafPtr; OVERRIDE;
  144.  
  145.                 { Debugging Methods }
  146.  
  147.                 PROCEDURE TMenu.Fields(PROCEDURE DoToField(fieldName: Str255;
  148.                                                            fieldAddr: Ptr;
  149.                                                            fieldType: INTEGER)); OVERRIDE;
  150.  
  151.  
  152.                 END;
  153.  
  154.         PROCEDURE InitUMenu;
  155.         { Call this at the start of your program, before creating any TMenu objects.
  156.         This can signal Failure. }
  157.  
  158.     IMPLEMENTATION
  159.  
  160.         {$I UMenu.inc1.p}
  161.  
  162. END.
  163.